package edu.ncet.desktop.client;

import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.BarDataProvider;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.extjs.gxt.charts.client.model.Scale;
import com.extjs.gxt.charts.client.model.ScaleProvider;
import com.extjs.gxt.charts.client.model.charts.BarChart;
import com.extjs.gxt.charts.client.model.charts.BarChart.BarStyle;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;

import edu.ncet.desktop.shared.BarChartResultModel;

public class GraphHelper {
	
	public static void drawGraph(ContentPanel cp, String graphTitle, ListStore<BarChartResultModel> store, final Scale scale )
	{
		drawGraph(cp,graphTitle,store,scale,380,360);
	}
	
	public static void drawGraph(ContentPanel cp, String graphTitle, ListStore<BarChartResultModel> store, final Scale scale , int width, int height )
	{
		cp.removeAll();
		Chart chart = new Chart("ncetdesktop/resources/chart/open-flash-chart.swf");
		
		ChartModel model = new ChartModel(graphTitle,
             "font-size: 14px; font-family: Verdana; text-align: center;");
		
		BarChart barChart = new BarChart(BarStyle.GLASS);
		
		chart.setSize(width, height);
		
		BarDataProvider provider = new BarDataProvider("value","label");
		
		model.setScaleProvider(new ScaleProvider(){
			public Scale calcScale(double min, double max) {
				return scale;
			}
		});
		
		provider.bind(store);
		barChart.setDataProvider(provider);
		
		model.addChartConfig(barChart);
		chart.setChartModel(model);
		cp.add(chart);
		cp.layout(true);
	}
}

